use std::collections::{HashMap};
impl Solution {
    pub fn minimum_card_pickup(cards: Vec<i32>) -> i32 {
        let mut mp=HashMap::<i32,usize>::new();
        let mut min_len:Option<usize>=None;
        let mut begin_ind=0;
        for (ind,val) in cards.into_iter().enumerate(){
            mp.entry(val).and_modify(|last_ind|{
                if min_len.is_none(){
                    min_len=Some(ind-*last_ind+1);
                }else{
                    if min_len.unwrap()>ind-*last_ind+1{
                        min_len=Some(ind-*last_ind+1);
                        begin_ind=*last_ind;
                    }
                }
                
                *last_ind=ind;
            }).or_insert(ind);
        };
        if let Some(ans)=min_len{
            ans as i32
        }else{
            -1
        }
    }
}